package name.marz.to.go.ahg.sonybank.executer;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import name.marz.to.go.ahg.common.util.HttpUtil;
import name.marz.to.go.ahg.core.AutoGetterHttpClient;
import name.marz.to.go.ahg.core.Parameters;
import name.marz.to.go.ahg.core.executer.AbstractPostExecuter;
import name.marz.to.go.ahg.core.responsehandler.DocumentResponseHandler;

import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.message.BasicNameValuePair;
import org.jsoup.nodes.Document;


public class LogoutExecuter extends AbstractPostExecuter<Document> {
	private Document doc;
	private DocumentResponseHandler handler;

	/**
	 * @param host
	 * @param uri
	 * @param client
	 * @param context
	 */
	public LogoutExecuter(URI uri, AutoGetterHttpClient client, Document doc) {
		super(uri,client);
		this.doc = doc;
		this.handler = new DocumentResponseHandler(client.getDefaultCharset());
		setPageName("ログアウト");
	}

	@Override
	protected List<NameValuePair> getRequestParameters() {
		Parameters parameters = HttpUtil.getParametersFromInputTags(doc);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(parameters.getNameValuePair("__sid"));
		params.add(parameters.getNameValuePair("__uid"));
		params.add(parameters.getNameValuePair("LoginKS"));
		params.add(new BasicNameValuePair("__type","0002"));
		return params;
	}

	@Override
	protected ResponseHandler<Document> getResponseHandler() {
		return handler;
	}
}
